package com.module.sys;

import java.io.IOException;
import java.util.Map;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
/**
 *
 * <解析工具类>
 * <将JSon报文解析成Java对象>
 *
 * @author  dengsq
 * @version  [1.0, Jun 22, 2011]
 * @see  [相关类/方法]
 * @since  [二代产品/消息处理组件]
 */
public class ResolveUnit
{
    /**
     * <解析报文>
     * <将报文解析成java对象>
     * @param message
     * @return
     * @see [类、类#方法、类#成员]
     */
    public static BeanUnit resolve(final String message){
        final ObjectMapper  objectMapper = new ObjectMapper();
        BeanUnit object = null ;
        try{
            object = objectMapper.readValue(message, BeanUnit.class);
        }catch (JsonParseException e){
            e.printStackTrace();
        }catch (JsonMappingException e){
            e.printStackTrace();
        }catch (IOException e){
            e.printStackTrace();
        }
        return object;
    }
    /**
     * <组建报文>
     * <将Map对象转换成Json格式的字符串>
     * @param map
     * @throws Exception
     * @see [类、类#方法、类#成员]
     */
    @SuppressWarnings("unchecked")
    public static String getJsonStr(Map map) throws Exception{
        ObjectMapper objectMapper = new ObjectMapper() ;
        String jsonStr = objectMapper.writeValueAsString(map);
        return jsonStr;
    }
}
